package com.qcby.service.impl;

import com.qcby.dao.TeacherDao;
import com.qcby.entity.Result;
import com.qcby.entity.Teacher;
import com.qcby.service.TeacherService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.web.servlet.server.Session;
import org.springframework.stereotype.Service;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import java.util.List;

@Service
public class TeacherServiceImpl implements TeacherService {
    @Autowired
    private TeacherDao teacherDao;

    @Override
    public Result login(Teacher teacher, HttpServletRequest request) {
        Teacher teacher1 = teacherDao.login(teacher);
        System.out.println(teacher1);
        if (teacher1 != null) {
            HttpSession session = request.getSession();
            session.setAttribute("teacher", teacher1);
            return Result.success(teacher1);
        } else {
            return Result.error("用户名或密码错误");
        }
    }

    @Override
    public Teacher findByWorkNumber(Teacher teacher) {
        return teacherDao.findByWorkNumber(teacher);
    }

    @Override
    public List<Teacher> SearchTeachers(Teacher teacher) {
        return teacherDao.SearchTeachers(teacher);
    }

    @Override
    public int AddTeacher(Teacher teacher) {
        return teacherDao.AddTeacher(teacher);
    }

    @Override
    public int UpdateTeacher(Teacher teacher) {
        return teacherDao.UpdateTeacher(teacher);
    }

    @Override
    public int DeleteTeacher(Integer id) {
        return teacherDao.DeleteTeacher(id);
    }

    @Override
    public List<Teacher> SearchClassTeacher(Integer id) {
        return teacherDao.SearchClassTeacher(id);
    }
}
